package javaweb.Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
@WebServlet("/s0")
public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        System.out.println(req.getQueryString());
        if ("admin".equals(username)&&"admin".equals(password)) {
            System.out.println("登陆成功!");
        }else {
            System.out.println("登陆失败");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader=req.getReader();
        String line;
        while ((line=reader.readLine())!=null){
            String[] parametersArr=line.split("&");
            String username=parametersArr[0].split("=")[1];
            String password=parametersArr[1].split("=")[1];
            System.out.println(line);
            if ("admin".equals(username)&&"admin".equals(password)) {
                System.out.println("登陆成功!");
            }else {
                System.out.println("登陆失败");
            }
        }
    }
}
